﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Santa_sAdventure.View
{
    class SplitterParticle
    {
        private Vector2 m_systemStartPosition;
        private Vector2 m_position;
        private Vector2 m_velocity;
        private Vector2 m_acceleration;
        private int m_direction;
        private int maxSpeed = 2;
        private int seed;

        public SplitterParticle(int a_seed, Vector2 a_systemStartPosition, int a_direction)
        {
            this.seed = a_seed;
            this.m_systemStartPosition = a_systemStartPosition;
            m_direction = a_direction;
            InitParticle();
        }

        // Update
        internal void Update(float a_elapsedTimeSeconds)
        {
            // Update particle position
            m_position = m_position + m_velocity * a_elapsedTimeSeconds;
            m_velocity = m_velocity + m_acceleration * a_elapsedTimeSeconds;
        }

        private void InitParticle()
        {
            // Init particles values
            Random rand = new Random(seed);
            this.m_position = new Vector2(m_systemStartPosition.X, m_systemStartPosition.Y);
            m_velocity = new Vector2(m_direction, (float)((rand.NextDouble() - 0.5f)));
            m_velocity.Normalize();
            m_velocity = m_velocity * ((float)rand.NextDouble() * 2 - 1 * maxSpeed);

            m_acceleration = new Vector2(0, 25);
        }

        // Draw
        internal void Draw(SpriteBatch spriteBatch, Camera camera, Texture2D sparkTexture)
        {
            // Draw the particle
            Rectangle sparkRec = camera.GetVisualRectangle(m_position.X, m_position.Y, 0.2f, 0.2f);
            spriteBatch.Draw(sparkTexture, sparkRec, Color.White);
        }
    }
}
